package com.brkj.personalCenter;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import com.brkj.httpInterface.BaseAjaxParams;
import com.brkj.httpInterface.HttpInterface;
import com.brkj.httpInterface.NomalResult;
import com.brkj.main.R;
import com.brkj.util.MyAjaxCallBack;
import com.brkj.util.MyApplication;
import com.brkj.util.view.BaseActivity;
import com.brkj.util.view.BaseCoreActivity;
import com.brkj.util.view.WidgetAnim;
import net.tsz.afinal.FinalHttp;

/**
 * Created by colin.ding on 2014/5/21.
 */
public class ChangePasswordActivity extends BaseActivity{

    private EditText oldpw1, oldpw2, newpw;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setAnimType(RIGHT_ENTER_LEFT_EXT);
        super.onCreate(savedInstanceState);

        setContentView(R.layout.change_password);

        setReturnBtn();
        setActivityTitle("修改密码");

        oldpw1 = (EditText) findViewById(R.id.oldpw1);
        oldpw2 = (EditText) findViewById(R.id.oldpw2);
        newpw = (EditText) findViewById(R.id.newpw);
    }

    public void changePW(View v){

        if(WidgetAnim.checkIfEmpty(this, oldpw1)){
            return;
        }

        if(WidgetAnim.checkIfEmpty(this, oldpw2)){
            return;
        }

        if(WidgetAnim.checkIfEmpty(this, newpw)){
            return;
        }

        if(!oldpw1.getText().toString().equals(oldpw2.getText().toString())){
            showToast("两次输入的旧密码不一致！");
            return;
        }

        BaseAjaxParams params = new BaseAjaxParams();
        params.put(HttpInterface.HIF_ChangePassword.params.UserID, MyApplication.myUserID);
        params.put(HttpInterface.HIF_ChangePassword.params.OldPassWord, oldpw1.getText().toString());
        params.put(HttpInterface.HIF_ChangePassword.params.NewPassWord, newpw.getText().toString());

        FinalHttp fh = new FinalHttp();
        fh.post(HttpInterface.HIF_ChangePassword.address, params, new MyAjaxCallBack<Object>((BaseCoreActivity)this) {
            @Override
            public void onSuccess(Object o) {
                super.onSuccess(o);

                if(NomalResult.doResult(o, ChangePasswordActivity.this)){
                    showToast("修改密码成功！");
                    finish();
                }else{
                    showToast("修改密码失败！");
                }
            }
        });
    }
}
